/*
 * @lc app=leetcode.cn id=1945 lang=typescript
 *
 * [1945] 字符串转化后的各位数字之和
 */

// @lc code=start
function getLucky(s: string, k: number): number {
    let sum = "";
    for (let i = 0; i < s.length; i++) {
        sum += (s.charCodeAt(i) - 96).toString();
    }

    while (k) {
        k--;
        sum = sum
            .split("")
            .reduce((col, cur) => {
                return (col += parseInt(cur));
            }, 0)
            .toString();
    }
    return parseInt(sum);
}
// @lc code=end
